package com.yanqu.road.server.cmd.match;

import com.yanqu.road.entity.match.MatchWeekRankRewardState;
import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.match.MatchModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/3/17 18:54
 */
@Cmd(code = GameProtocol.S_VARIETY_GET_WEEK_RANK_LIST, desc = "杂艺周榜列表")
public class GetVarietyWeekRankListCmd extends AbstractCommand {
    private int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VarietyProto.GetWeekRankListReqMsg msg = VarietyProto.GetWeekRankListReqMsg.parseFrom(packet.getBytes());
        type = msg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        VarietyProto.GetWeekRankListCrossReqMsg.Builder reqMsg = VarietyProto.GetWeekRankListCrossReqMsg.newBuilder();
        long groupId = GameServer.getInstance().getServerId();
//        MatchServerGroup group = MatchServerGroupMgr.getServerGroupByServerId(GameServer.getInstance().getServerId());
//        if (group != null) {
//            groupId = group.getGroupId();
//        }
        reqMsg.setGroupId(groupId);
        MatchModule matchModule = player.getModule(MatchModule.class);
        int weekId = matchModule.getRankListWeekIdByType(type);
        reqMsg.setWeekId(weekId);
        reqMsg.setIsGetReward(false);
        MatchWeekRankRewardState state = matchModule.getRewardStateMap().get(weekId);
        if (state != null) {
            reqMsg.setIsGetReward(state.isGetReward());
        }
        player.sendPacket(CrossProtocol.C_VARIETY_GET_RANK_LIST, reqMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
